home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH2 / SRC / PENS.FRM < prev    next >
Text File  |  1995-12-22  |  2KB  |  86 lines

  1. VERSION 4.00
  2. Begin VB.Form PenForm 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Pens and Brushes"
  5.    ClientHeight    =   2115
  6.    ClientLeft      =   1605
  7.    ClientTop       =   2400
  8.    ClientWidth     =   6690
  9.    Height          =   2805
  10.    Left            =   1545
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   141
  13.    ScaleMode       =   3  'Pixel
  14.    ScaleWidth      =   446
  15.    Top             =   1770
  16.    Width           =   6810
  17.    Begin VB.Menu mnuFile 
  18.       Caption         =   "&File"
  19.       Begin VB.Menu mnuFileExit 
  20.          Caption         =   "E&xit"
  21.       End
  22.    End
  23. End
  24. Attribute VB_Name = "PenForm"
  25. Attribute VB_Creatable = False
  26. Attribute VB_Exposed = False
  27. Option Explicit
  28.  
  29.  
  30. Private Sub Form_Resize()
  31. Dim pen As Integer
  32. Dim old_pen As Integer
  33. Dim brush As Integer
  34. Dim old_brush As Integer
  35. Dim s As Integer
  36. Dim Y1 As Integer
  37. Dim Y2 As Integer
  38. Dim x As Integer
  39. Dim dx As Integer
  40. Dim wid As Integer
  41. Dim i As Integer
  42.  
  43.     Cls
  44.     
  45.     ' Figure out where to put the ellipses.
  46.     Y1 = 10
  47.     Y2 = ScaleHeight - 10
  48.     wid = (ScaleWidth - 70) / 6
  49.     x = 10
  50.         
  51.     For i = 0 To 5
  52.         ' Create a blue pen, width = 1, style = i.
  53.         pen = CreatePen(i, 1, vbBlue)
  54.         ' Select the pen remembering the old one.
  55.         old_pen = SelectObject(hDC, pen)
  56.         
  57.         ' Create the brush.
  58.         brush = CreateHatchBrush(i, vbMagenta)
  59.         ' Select the brush remembering the old one.
  60.         old_brush = SelectObject(hDC, brush)
  61.         
  62.         ' Draw an ellipse.
  63.         s = Ellipse(hDC, x, Y1, x + wid, Y2)
  64.         x = x + wid + 10
  65.         
  66.         ' Select the old pen.
  67.         pen = SelectObject(hDC, old_pen)
  68.         ' Delete the new pen to free its resources.
  69.         s = DeleteObject(pen)
  70.         
  71.         ' Select the old brush.
  72.         brush = SelectObject(hDC, old_brush)
  73.         ' Delete the new brush to free its resources.
  74.         s = DeleteObject(brush)
  75.     Next i
  76.     
  77.     Refresh
  78. End Sub
  79.  
  80.  
  81. Private Sub mnuFileExit_Click()
  82.     Unload Me
  83. End Sub
  84.  
  85.  
  86.